/*
 * CBulletDebugDrawer.h
 *
 *  Created on: 15.10.2012
 *      Author: Kirill Blinov
 *     License: LGPL
 */

#ifndef CBULLETDEBUGDRAWER_H_
#define CBULLETDEBUGDRAWER_H_

#include "../BasicTypes.h"
#include <bullet/btBulletDynamicsCommon.h>
#include <boost/thread/mutex.hpp>
#include <vector>

class CBulletDebugDrawer : public btIDebugDraw
{
private:
	struct DebugLine
	{
		DebugLine( const btVector3& FirstPoint,
					const btVector3& SecondPoint,
					const btVector3& Color) : firstPoint(FirstPoint), secondPoint(SecondPoint), color(Color)
		{

		}
		btVector3 firstPoint, secondPoint;
		btVector3 color;
	};

	static CBulletDebugDrawer* instance;

	std::vector<DebugLine> objectsToDraw;

	boost::mutex internalMutex;

	DebugDrawModes debugMode;
private:
	CBulletDebugDrawer();
	virtual ~CBulletDebugDrawer();

public:
	static CBulletDebugDrawer* GetInstance()
	{
		if ( NULL == instance )
		{
			instance = new CBulletDebugDrawer();
		}
		return instance;
	};

	virtual void	drawLine(const btVector3& from,const btVector3& to,const btVector3& color);
	virtual void	drawContactPoint(const btVector3& PointOnB,const btVector3& normalOnB,btScalar distance,int lifeTime,const btVector3& color);
	virtual void	reportErrorWarning(const char* warningString);
	virtual void	draw3dText(const btVector3& location,const char* textString);
	virtual void	setDebugMode(int DebugMode);
	virtual int	getDebugMode() const;

	void OpenGlDraw( glm::mat4 ProjectionMatrix, glm::mat4 ViewMatrix );
};

#endif /* CBULLETDEBUGDRAWER_H_ */
